package _04try_catch的使用注意;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Demo {
    public static void main(String[] args) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //try_catch代码块多个异常使用多个catch块抓取
        try {
            Date date = sdf.parse("2009-10-1");
            System.out.println("try此段代码被执行了");//不会被执行
            int a = 1/0;
            int[] i = {1,2};
            System.out.println(i[3]);
        } catch (ParseException e) {
            System.out.println("格式不匹配");

        } catch (ArrayIndexOutOfBoundsException e){
            System.out.println("数组越界异常");
        } catch (ArithmeticException e){
            System.out.println(e.getMessage());
        }
    }
}
